package com.cms.gdm.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cms.gdm.entity.GuideEntity;
import com.cms.gdm.entity.vo.ProjectClientVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cms.gdm.entity.ProjectEntity;
import com.cms.gdm.service.ProjectService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-15 10:50:55
 */
@RestController
@RequestMapping("gdm/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    /**
     * 根据学生ID查询毕业设计的详细信息
     */
    @RequestMapping("/selectProjectByStudentId/{studentId}")
    //@RequiresPermissions("gdm:project:list")
    public R selectProjectByStudentId(@PathVariable Long studentId){
        ProjectClientVo projectClientVo = projectService.selectProjectByStudentId(studentId);

        return R.ok().put("projectClientVo", projectClientVo);
    }

    /**
     * 根据guideId查询论文
     */
    @RequestMapping("/selectProjectByGuide/{guideId}")
    //@RequiresPermissions("gdm:project:list")
    public R selectProjectByGuide(@PathVariable Long guideId){
        ProjectEntity projects = projectService.selectProjectByGuide(guideId);

        return R.ok().put("projects", projects);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("gdm:project:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = projectService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/listGroup")
    //@RequiresPermissions("gdm:project:list")
    public R listGroup(@RequestParam Map<String, Object> params){
        PageUtils page = projectService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("gdm:project:info")
    public R info(@PathVariable("id") Long id){
		ProjectEntity project = projectService.getById(id);

        return R.ok().put("project", project);
    }

    /**
     * 教师修改学生论文的批注版
     */
    @RequestMapping("/updateProjectByTeacher")
    //@RequiresPermissions("gdm:guide:update")
    public R updateProjectByTeacher(@RequestParam("guideId") Long guideId, @RequestParam("rAddress") String rAddress){
        ProjectEntity projectEntity = new ProjectEntity();
        projectEntity.setGuideId(guideId);
        projectEntity.setRAddress(rAddress);
        projectService.updateProjectByTeacher(projectEntity);

        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("gdm:project:save")
    public R save(@RequestBody ProjectEntity project){
		projectService.save(project);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gdm:project:update")
    public R update(@RequestBody ProjectEntity project){
		projectService.updateById(project);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gdm:project:delete")
    public R delete(@RequestBody Long[] ids){
		projectService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
